package com.example.controller;


import com.example.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
/**
 * SpringBoot中使用Thymeleaf
 */
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {


    /**
     * 跳转文本表达式页面
     * @param model 模型对象,封装数据
     * @param session 会话对象,封装数据
     * @notice model与session异同点可参照博客:
     *         https://blog.csdn.net/Hello_ChenLiYan/article/details/106411452
     * @return
     */
    @RequestMapping("/variable")
    public String varEL(Model model, HttpSession session){
        model.addAttribute("result",108+921);
        Student student01 = new Student();
        student01.setName("Emily");
        student01.setPhoneNumber("92109210921");
        model.addAttribute("student01",student01);
        Student student02 = new Student();
        student02.setName("Karry");
        student02.setAddress("HUEL");
        session.setAttribute("student02",student02);
        return "variable";
    }


    @RequestMapping("/Choosevariable")
    public String Choosevariable(Model model, HttpSession session){
        Student student02 = new Student();
        student02.setName("Karry");
        student02.setAddress("Chong Qing");
        session.setAttribute("student02",student02);
        return "Choosevariable";
    }


    /**
     * 跳转链接表达式页面
     * @return
     */
    @RequestMapping("/urlEL")
    public String varEL(){
        return "url_el";
    }


    /**
     * 跳转消息表达式页面
     * @return
     */
    @RequestMapping("/message")
    public String message(){
        return "message";
    }

    /**
     * 跳转片段表达式页面
     * @return
     */
    @RequestMapping("/fragment")
    public String fragment(Model model){
        return "footer";
    }

    /**
     * 跳转首页
     * @return
     */
    @RequestMapping("/toIndex")
    public String toIndex(){
        return "index";
    }


}
